@include keyframes(container-rotate) {
  to { @include transform(rotate(360deg)) }
}

@include keyframes(fill-unfill-rotate) {
  12.5% { @include transform(rotate(135deg));  } /* 0.5 * ARCSIZE */
  25%   { @include transform(rotate(270deg));  } /* 1   * ARCSIZE */
  37.5% { @include transform(rotate(405deg));  } /* 1.5 * ARCSIZE */
  50%   { @include transform(rotate(540deg));  } /* 2   * ARCSIZE */
  62.5% { @include transform(rotate(675deg));  } /* 2.5 * ARCSIZE */
  75%   { @include transform(rotate(810deg));  } /* 3   * ARCSIZE */
  87.5% { @include transform(rotate(945deg));  } /* 3.5 * ARCSIZE */
  to    { @include transform(rotate(1080deg)); } /* 4   * ARCSIZE */
}

@include keyframes(left-spin) {
  from { @include transform(rotate(130deg)); }
  50% { @include transform(rotate(-5deg)); }
  to { @include transform(rotate(130deg)); }
}

@include keyframes(right-spin) {
  from { @include transform(rotate(-130deg)); }
  50% { @include transform(rotate(5deg)); }
  to { @include transform(rotate(-130deg)); }
}

@include keyframes(fade-in) {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@include keyframes(fade-out) {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}

.spinner {
  display: inline-block;
  position: relative;
  width: 28px;
  height: 28px;
  border-color: #4285f4;

  & .circle {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    box-sizing: border-box;
    height: 100%;
    border-width: 3px;
    border-style: solid;
    border-color: inherit;
    border-bottom-color: transparent !important;
    border-radius: 50%;
  }

  // Patch the gap that appear between the two adjacent div.circle-clipper while the
  // spinner is rotating (appears on Chrome 38, Safari 7.1, and IE 11).
  & .gap-patch {
    position: absolute;
    box-sizing: border-box;
    top: 0;
    left: 45%;
    width: 10%;
    height: 100%;
    overflow: hidden;
    border-color: inherit;

    & .circle {
      width: 1000%;
      left: -450%;
    }
  }

  & .circle-clipper {
    display: inline-block;
    position: relative;
    width: 50%;
    height: 100%;
    overflow: hidden;
    border-color: inherit;

    &.left .circle {
      border-right-color: transparent !important;
      @include transform(rotate(129deg));
      @include animation(left-spin 1333ms cubic-bezier(0.4, 0.0, 0.2, 1) infinite both);
    }

    &.right .circle {
      left: -100%;
      border-left-color: transparent !important;
      @include transform(rotate(-129deg));
      @include animation(right-spin 1333ms cubic-bezier(0.4, 0.0, 0.2, 1) infinite both);
    }

    & .circle {
      width: 200%;
    }
  }

  &.cooldown {
    /* duration: SHRINK_TIME */
    @include animation(fade-out 400ms cubic-bezier(0.4, 0.0, 0.2, 1) both);
  }
}

.spinner-container {
  width: 100%;
  height: 100%;
  border-color: inherit;

  /* duration: 360 * ARCTIME / (ARCSTARTROT + (360-ARCSIZE)) */
  @include animation(container-rotate 1568ms linear infinite);
}

.spinner-layer {
  position: absolute;
  width: 100%;
  height: 100%;
  opacity: 1;
  border-color: inherit;
  /* durations: 4 * ARCTIME */
  @include animation(fill-unfill-rotate 5332ms cubic-bezier(0.4, 0.0, 0.2, 1) infinite both);
}